package com.zwj.grpcspringcloudconsumer;

import com.zwj.grpc.cloud.lib.HelloReply;
import com.zwj.grpc.cloud.lib.HelloRequest;
import com.zwj.grpc.cloud.lib.SimpleGrpc;
import io.grpc.Channel;
import net.devh.boot.grpc.client.inject.GrpcClient;
import org.springframework.stereotype.Service;

@Service
public class SimpleClientService {

    //一般情况下我们不注入Channel，建议注入Stub
    @GrpcClient("grpc-spring-cloud-provider")
    private Channel serverChannel;

    @GrpcClient("grpc-spring-cloud-provider")
    private SimpleGrpc.SimpleBlockingStub stub;


    public String sendMessage(String name) {
       // SimpleGrpc.SimpleBlockingStub stub= SimpleGrpc.newBlockingStub(serverChannel);
        HelloReply response = stub.sayHello(HelloRequest.newBuilder().setName(name).build());
        return response.getMessage();
    }
}
